/**
 *
 */
package com.scitc.pleasurevideo.helper;

import android.os.Handler;


/**
 * @author tata
 *
 */
public class ThreadHelper {

    // private static Handler keepHandler =new Handler();

    public static interface ThreadListener {
        public void onResult(Object input);

        public Object getInput();
    }

    public static interface BackThreadListener {
        public void background();

    }

    public static void run(final BackThreadListener listener) {
        TaskMgr.getTaskMgr().executeTask2(new Runnable() {

            @Override
            public void run() {
                try {
                    listener.background();
                } catch (Exception e) {
                }
            }
        });

    }

    public static void run(final ThreadListener listener, final Handler handler) {
        run(listener, handler, 0);
    }

    public static void run(final ThreadListener listener, final Handler handler, final long delay) {

        TaskMgr.getTaskMgr().executeTask2(new Runnable() {

            @Override
            public void run() {

                final Object input = listener.getInput();

                if (input == null) {
                    return;
                }

                handler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        listener.onResult(input);
                    }
                }, delay);

            }
        });

    }

}
